Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitswap: fix a minor data race #3036

Merged
merged 1 commit into from
Aug 4, 2016
Merged

bitswap: fix a minor data race #3036

merged 1 commit into from
Aug 4, 2016

Conversation

whyrusleeping
Copy link
Member

race detector picked up a minor race condition, Since loop iteration reuses the same local variable, its not safe to take its address and use it concurrently. The fix is to rebind the variable into a controlled scope (creating a new variable) and taking the address of that to pass outwards.

License: MIT
Signed-off-by: Jeromy [email protected]

@Kubuxu
Copy link
Member

Kubuxu commented Aug 4, 2016

LGTH, but it would be great to have this explanation either as commit message or a comment.

race detector picked up a minor race condition, Since loop iteration
reuses the same local variable, its not safe to take its address and use
it concurrently. The fix is to rebind the variable into a controlled
scope (creating a new variable) and taking the address of that to pass
outwards.

License: MIT
Signed-off-by: Jeromy <[email protected]>
@whyrusleeping
Copy link
Member Author

@Kubuxu added more description to the commit message

@Kubuxu
Copy link
Member

Kubuxu commented Aug 4, 2016

Great, thank you. LGTM

@whyrusleeping whyrusleeping merged commit 2a4560c into master Aug 4, 2016
@whyrusleeping whyrusleeping deleted the fix/wlist-race branch August 4, 2016 10:46
@@ -173,6 +173,7 @@ func (bs *Bitswap) rebroadcastWorker(parent context.Context) {
case <-broadcastSignal.C: // resend unfulfilled wantlist keys
log.Event(ctx, "Bitswap.Rebroadcast.active")
for _, e := range bs.wm.wl.Entries() {
e := e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add:

e := e // prevent data race

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants